<?php

    namespace app\admin\controller;
    use think\Controller;
    use app\admin\model\Course;
    use app\admin\model\Classes;
    use app\admin\model\Teacher;
    use think\Request;
    use think\Db;

    class Courseshow extends Controller{


        public function index(){
            //volist遍历数据库
            $role = New Course();
            $data = $role -> course_list();
            //dump($data->toArray());
            $this->assign('course_list',$data);

            //新添课程里面的班级volist
            $classes = New Classes();
            $classdata = $classes -> classno_list();
            // dump($classdata->toArray());
            $this->assign('classno_list',$classdata);

            //新添课程里面的教师姓名volist
            $teacher = New Teacher();
            $tnamedata = $teacher -> tn_list();
            // dump($classdata->toArray());
            $this->assign('tn_list',$tnamedata);

            
            //修改课程里面的班级volist
            $cclasses = New Classes();
            $classnodata = $cclasses -> change_classno_list();
            // dump($classdata->toArray());
            $this->assign('change_classno_list',$classnodata);


            //修改课程里面的教师姓名volist
            $teachername = New Teacher();
            $t_namedata = $teachername -> change_tn_list();
            // dump($classdata->toArray());
            $this->assign('change_tn_list',$t_namedata);

            return $this->fetch();
        }

        public function newcourse(){
            if(request()->isPost()){
                $course=new Course();
                $data=input('post.');
                //var_dump($data);
                $num=$course->insert($data);
                if($num==1){
                    $this->success("新添成功","admin/courseshow/index");
                }else{
                    $this->error('新添失败');
                }
            }
            return $this->fetch();
        }

        
        public function coursedelete(Request $Request){
            $id = request()->param();
            // var_dump($id);
            
            $res = DB::table("course")->delete($id);
            if($res){
                $this->success("OK","admin/courseshow/index");
            }else{
                $this->error();
            }
        }

        public function changecourse(){

            if(request()->isPost()){
                $course=new Course();
                $data=input('post.');
                // var_dump($data);
                $num=$course->change($data);
                
                if($num==1){
                    $this->success("修改成功","admin/Courseshow/index");
                }else{
                    $this->error('修改失败');
                }
            }
        }



    }

?>